package com.example.anodemo.mapper;

import com.example.anodemo.model.Product;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

@Mapper
public interface ProductMapper {


    /**
     *  在查询结果是 集合时
     *  如何实现 一对一的关联
     * */

    @Select("select * from product")
    @Results(value = {
            @Result(column = "product_id",property = "productId")
    })
    List<Product> selectAll();

    @Select("select * from product where product_id = #{productId}")
    @Results(value = {
            @Result(column = "product_id",property = "productId"),
            @Result(column = "name",property = "name"),
            @Result(column = "product_typeId",property = "productType",
                    one = @One(select = "com.example.anodemo.mapper.DictMapper.selectById"
                            ,fetchType = FetchType.LAZY)
            )
    })
    Product selectById(@Param("productId") Integer productId);

    @Select("select * from product where name = #{name}" +
            " or product_id #{productId}")

    List<Product> selectByExample(Product product);

    @Insert("insert into product(product_name,price) value(#{name},#{price})")
    int insert(Product product);

    /**
     *  如何使用注解方式
     *   完成 修改和删除
     * */



}
